// #ifndef VUE3
import Vue from 'vue'
import App from './App'
// 引入vuex
import store from "@/store/store.js"
// 引入uview插件
import uView from '@/uni_modules/uview-ui'
Vue.use(uView)
//导入第三方网路数据请求包
import {
  $http
} from '@escook/request-miniprogram'
//挂载到顶级对象上
uni.$http = $http

//配置请求拦截器
$http.beforeRequest = function(options) {
  uni.showLoading({
    title: '数据加载中'
  })
  options.header = {
    'Authorization': 'Bearer ' + uni.getStorageSync('token')
  }
}
//配置响应拦截器
$http.afterRequest = function(response) {
  if (response.data.code == 401) {
    uni.$showMsg('未登录,请立即登录')
    setTimeout(() => {
      uni.redirectTo({
        url: '/subpkg/loginAndRegister/loginAndRegister'
      })

    }, 1500)
  }
  uni.hideLoading()
}
//配置请求根路径
$http.baseUrl = 'https://www.scbjlr.com/api'

//封装弹框的方法
uni.$showMsg = function(title = '数据请求失败！', duration = 1500) {
  uni.showToast({
    title,
    duration,
    icon: 'none'
  })
}

Vue.config.productionTip = false

App.mpType = 'app'

const app = new Vue({
  ...App,
  store
})
app.$mount()
// #endif

// #ifdef VUE3
import {
  createSSRApp
} from 'vue'
import App from './App.vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif